-- This is no gadget but a class file!
-- An object of this class represents an Engine in the view of the game.
	-- objects of further classes are created that handle specific parts of the Engine (ie the LevelHandler)

include("LuaRules/Classes/OOLuaClass.lua")
include("LuaRules/Classes/OOLevelHandler.lua")

Engine = {}
local Engine_mt = Class(Engine)

--Constructor
function Engine:new(unitID,unitDefID,teamID)
  -- make instance of ExpEngine instead - thats constructor should call the LevelHandler:SetUnitValues(unitID,unitDefID,0)
  -- would it be as one of the member variables ??
  return setmetatable( 	{--declare member variables at this place:
  						unitID=unitID,
  						unitDefID=unitDefID,
  						teamID=teamID,
  						playerID=0,	-- as stated below - non functional as of now
						isAlive = true,
						lvlHandler = LevelHandler:new(unitID,unitDefID,teamID), -- yes ?
  					 	-- currentLevel=0,	-- do we set here and route through ? or not set, and handle routing differently ?
  					 	-- currentXP=0,									-- perhaps in style of = expengine.currentXP or such
  					 	-- abilityLvLs = {[0] = 0, [1] = 0},	-- load from config, or tell to set from outside (for non 0 - 0, other tables). Probably load from config here
  					 	--lvlUpElementsShown = false,
  					 	--abilityButtonsShown = {[0] = false, [1] = false}	-- this would depend on abilityLvls
  					 	}, Engine_mt)
end


--returns the UnitID of this engine
function Engine:GetUnitID()
  return self.unitID
end
	
--sets the UnitID of this engine (ie on respawn)
function Engine:SetUnitID(newUnitID)	-- different function name may be appropriate, as we're doing far more than just telling it the new unitID - more like Engine:Respawned or Engine:NewUnit/ChangeUnit/SwitchUnit
  self.unitID = newUnitID				-- might also want to change it into the part that belongs here, and then calling the part that belongs in ExpEngine (ie setting stats, abilities, etc.)
  self.lvlHandler:Respawn(self.unitID,self.unitDefID,self.teamID)	-- ah, but now that it's an actual object rather than a collection of functions is this the proper way to do it ?
		-- will that work?														-- perhaps call own instance ?? ie lvlHandler:Respawn ?
end

--returns the UnitDefID of this engine
function Engine:GetUnitDefID()
  return self.unitDefID
end

--returns the PlayerID of this engine
function Engine:GetPlayerID()	-- non functional atm, correct ? I guess we're not using it yet anyway, so no prob
  return self.playerID
end

function Engine:GetTeamID()
  return self.teamID
end


function Engine:SetDead()
	self.isAlive = false
end

function Engine:SetAlive()
	self.isAlive = true
end

function Engine:IsAlive()
	return self.isAlive
end

--------------------------------------------
-- need to see if "routing" of these function calls will work like this
-----------------------------------------
-- LevelHandler Class functions

function Engine:GetCurrentLevel()
	return self.lvlHandler:GetCurrentLevel()
end

function Engine:GetCurrentXP()
	return self.lvlHandler:GetCurrentXP()
end

function Engine:AddXP(xpToAdd)
	self.lvlHandler:AddXP(xpToAdd,self.unitID,self.unitDefID,self.teamID)
end

function Engine:OpenLevelUps()
	return self.lvlHandler:OpenLevelUps()
end

function Engine:GetAbilityLvl(abilityID)
	-- Spring.Echo("AbilityLvl Query being routed by MetaEngine")
	return self.lvlHandler:GetAbilityLvl(abilityID)
end

function Engine:AddAbilityLvl(abilityID)
	self.lvlHandler:AddAbilityLvl(abilityID,self.unitID,self.unitDefID,self.teamID)
end
-------------------------------------
